home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / DataTruncation.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  113 lines

  1. /*
  2.  * @(#)DataTruncation.java    1.6 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.sql;
  16.  
  17. /**
  18.  * <P>When JDBC unexpectedly truncates a data value, it reports a
  19.  * DataTruncation warning (on reads) or throws a DataTruncation exception
  20.  * (on writes).
  21.  *
  22.  * <P>The SQLstate for a DataTruncation is "01004".
  23.  */
  24.  
  25. public class DataTruncation extends SQLWarning {
  26.  
  27.     /**
  28.      * <P>Create a DataTruncation object. The SQLState is initialized
  29.      * to 01004, the reason is set to "Data truncation" and the
  30.      * vendorCode is set to the SQLException default.
  31.      *
  32.      * @param index The index of the parameter or column value
  33.      * @param parameter true if a parameter value was truncated
  34.      * @param read true if a read was truncated
  35.      * @param dataSize the original size of the data
  36.      * @param transferSize the size after truncation 
  37.      */
  38.     public DataTruncation(int index, boolean parameter, 
  39.               boolean read, int dataSize, 
  40.               int transferSize) {
  41.     super("Data truncation", "01004");
  42.     this.index = index;
  43.     this.parameter = parameter;
  44.     this.read = read;
  45.     this.dataSize = dataSize;
  46.     this.transferSize = transferSize;
  47.     DriverManager.println("    DataTruncation: index(" + index + 
  48.                   ") parameter(" + parameter +
  49.                   ") read(" + read +
  50.                   ") data size(" + dataSize +
  51.                   ") transfer size(" + transferSize + ")");
  52.     }
  53.  
  54.     /**
  55.      * Get the index of the column or parameter that was truncated.
  56.      *
  57.      * <P>This may be -1 if the column or parameter index is unknown, in 
  58.      * which case the "parameter" and "read" fields should be ignored.
  59.      *
  60.      * @return the index of the truncated paramter or column value.
  61.      */
  62.     public int getIndex() {
  63.     return index;
  64.     }
  65.  
  66.     /**
  67.      * Is this a truncated parameter value?
  68.      *
  69.      * @return True if the value was a parameter; false if it was a column value.
  70.      */
  71.     public boolean getParameter() {
  72.     return parameter;
  73.     }
  74.  
  75.     /**
  76.      * Was this a read truncation?
  77.      *
  78.      * @return True if the value was truncated when read from the database; false
  79.      * if the data was truncated on a write.
  80.      */
  81.     public boolean getRead() {
  82.     return read;
  83.     }
  84.  
  85.     /**
  86.      * Get the number of bytes of data that should have been transferred.
  87.      * This number may be approximate if data conversions were being
  88.      * performed.  The value may be "-1" if the size is unknown.
  89.      *
  90.      * @return the number of bytes of data that should have been transferred
  91.      */
  92.     public int getDataSize() {
  93.     return dataSize;
  94.     }
  95.  
  96.     /**
  97.      * Get the number of bytes of data actually transferred.
  98.      * The value may be "-1" if the size is unknown.
  99.      *
  100.      * @return the number of bytes of data actually transferred
  101.      */
  102.     public int getTransferSize() {
  103.     return transferSize;
  104.     }
  105.  
  106.     private int index;
  107.     private boolean parameter;
  108.     private boolean read;    
  109.     private int dataSize;
  110.     private int transferSize;
  111.  
  112. }
  113.